package com.goods.business.service.imp;

import com.github.pagehelper.PageInfo;
import com.goods.business.mapper.SourceMapper;
import com.goods.business.service.SourceService;
import com.goods.common.model.business.Supplier;
import com.goods.common.utils.ListPageUtils;
import com.goods.common.vo.business.SupplierVO;
import com.goods.common.vo.system.PageVO;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class SourceServiceImpl implements SourceService {

    @Autowired
    private SourceMapper sourceMapper;

    /**
     * 获取供应商集合
     * @param pageNum
     * @param pageSize
     * @param name
     * @return
     */
    @Override
    public PageVO<Supplier> findSupplierList(Integer pageNum, Integer pageSize, String name,String address,String contact) {
        List<Supplier> supplierList = sourceMapper.findSupplierList(name,address,contact);
        PageInfo<Supplier> pageInfo = new PageInfo<>(supplierList);
        return new PageVO<>(pageInfo.getTotal(),ListPageUtils.page(supplierList,pageSize,pageNum));
    }

    /**
     * 添加物资来源信息
     * @param supplierVO
     * @return
     */
    @Override
    public void add(SupplierVO supplierVO) {
        supplierVO.setCreateTime(new Date());
        supplierVO.setModifiedTime(new Date());
        sourceMapper.insertSupplier(supplierVO);
    }

    /**
     * 删除物资来源信息
     * @param id
     * @return
     */
    @Override
    public void delete(Long id) {
        sourceMapper.delete(id);
    }

    /**
     * 回显物资来源信息
     * @param id
     */
    @Override
    public Supplier getById(Long id) {
        Supplier supplier = sourceMapper.getById(id);
        return supplier;
    }

    /**
     * 修改物资信息
     * @param supplierVO
     * @param id
     */
    @Override
    public void update(SupplierVO supplierVO, Long id) {
        sourceMapper.update(supplierVO,id);
    }
}
